<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        fixed
        prop="id"
        label="编号"
        width="150">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="150">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="150">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="300">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="300">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="200">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      background
      layout="sizes, prev, pager, next"
      :page-sizes="[8, 20, 100, 200]"
      :total="total"
      align="right"
      @current-change="goPage"
      @size-change="goPageSize">
    </el-pagination>
  </div>
</template>

<script>

/*引入Axios, 这是局部的写法，全局需要在main.js中引入*/
// import axios from "axios"

export default {
  name: 'user',
  data () {
    return {
      tableData:[],
      total:0,
      currentPage:1,
      pageSize:8
    }
  },
  mounted() {
    this.list()
  },
  methods:{
    handleClick(row) {
      console.log(row);
    },
    goPage(currentPage){
      this.currentPage = currentPage;
      this.list()
    },
    goPageSize(pageSize){
      this.pageSize = pageSize;
      this.currentPage = 1;
      this.list()
    },
    list(){
      this.$http.get("/user/loadAll",{"currentPage":this.currentPage,"pageSize":this.pageSize})
        .then(result=>{
          this.tableData = result.data.data;
          this.total = result.data.totals;
        })
        .catch(error=>{
          console.log(error);
          alert("系统繁忙，请稍后再试！")
        })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
